﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.Menu;
using AnQinFrameWorkAPI.Entity.SystemCore.View.Menu;
using AnQinFrameWorkAPI.Service.SystemCore;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.SystemCore;

/// <summary>
///     菜单API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "SystemCore")]
public class MenuController : ControllerBase
{
    //业务接口
    private readonly MenuService _menuService;

    //构造注入
    public MenuController(MenuService menuService)
    {
        _menuService = menuService;
    }

    /// <summary>
    ///     获取菜单列表
    /// </summary>
    [ProducesResponseType(typeof(MenuView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetMenuList([FromQuery] MenuSearchDTO menuSearchDTO)
    {
        var response = await _menuService.GetMenuList(menuSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     获取菜单详情列表
    /// </summary>
    [ProducesResponseType(typeof(MenuDetailView), 200)]
    [HttpGet("GetMenuDetailList")]
    public async Task<IActionResult> GetMenuDetailList([FromQuery] MenuSearchDTO menuSearchDTO)
    {
        var response = await _menuService.GetMenuDetailList(menuSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     获取用户菜单详情列表
    /// </summary>
    [ProducesResponseType(typeof(MenuDetailView), 200)]
    [HttpGet("GetUserMenuDetailList")]
    public async Task<IActionResult> GetUserMenuDetailList()
    {
        var response = await _menuService.GetUserMenuDetailList();
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增菜单
    /// </summary>
    /// <params name="menuAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddMenu([FromBody] MenuAddDTO menuAddDTO)
    {
        var response = await _menuService.AddMenu(menuAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑菜单
    /// </summary>
    /// <params name="menuUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutMenu([FromBody] MenuUpdateDTO menuUpdateDTO)
    {
        var response = await _menuService.PutMenu(menuUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除菜单
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteMenu([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _menuService.DeleteMenu(deleteDTO);
        return StatusCode(response.Status, response);
    }
}